package com.wmyg.antifake.gs1.ns2.converters;

import com.wmyg.antifake.gs1.ns2.SpecialString;
import com.wmyg.antifake.gs1.ns2.TSDBasicProductInformationModule;
import com.wmyg.antifake.gs1.ns2.basic.StringAVP;
import org.dom4j.Element;

import java.util.List;

/**
 * @program: antifake
 * @description: 基本商品信息转换器
 * @author: wong
 * @create: 19-4-23
 */
public class BasicProductInformationConverter {

    protected static TSDBasicProductInformationModule convert(Element infoElement) {
        TSDBasicProductInformationModule module = new TSDBasicProductInformationModule();
        List<Element> children = infoElement.elements();
        for (Element e :
                children) {
            switch (e.getName()) {
                case "productName":
                    module.setProductName(new SpecialString(e));
                    break;
                case "consumerMarketingDescription":
                    module.setConsumerMarketingDescription(new SpecialString(e));
                    break;
                case "gpcCategoryCode":
                    module.setGpcCategoryCode(e.getText());
                    break;
                case "brandNameInformation":
                    module.setBrandNameInformation(BrandNameConverter.converter(e));
                    break;
                case "productInformationLink":
                    module.setProductInformationLink(LinkConverter.converter(e));
                    break;
                case "imageLink":
                    module.getImageLinks().add(LinkConverter.converter(e));
                    break;
                case "packagingSignatureLine":
                    module.setPackagingSignatureLine(PackagingSignatureLineConverter.convert(e));
                    break;
                case "avpList":
                    List<Element> avps = e.elements();
                    for (Element avp :
                            avps) {
                        module.getAvpList().add(new StringAVP(avp));
                    }
                    break;
                default:
                    module.setMap(MapConverter.elementToMap(e));
            }
        }
        return module;
    }

}
